package unibratec.projeto;

import java.io.IOException;
import java.util.List;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.provider.ContactsContract.CommonDataKinds.Event;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

public class PrincipalActivity extends MapActivity implements LocationListener {

	private List<Overlay> mapOverlays;
	private Drawable drawable;
	private ItemizedOverlay itemizedOverlay;
	private MapView mapa;
	private MapController mapcontroller;
	private PopupWindow pw;
	private TextView txtLocal;
	private TextView txtDesc;
	private GeoPoint p;
	
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mapa = (MapView) findViewById(R.id.mapa);
        mapa.setBuiltInZoomControls(true);
        mapa.setStreetView(true);
        mapa.setClickable(true);
        
        mapOverlays = mapa.getOverlays();
        drawable = getResources().getDrawable(R.drawable.ponto);
        itemizedOverlay = new ItemizedOverlay(drawable, mapa);
        
        GeoPoint point = new GeoPoint((int)(-8.048245 * 1E6), (int)(-34.921503 * 1E6));
    	OverlayItem overlayitem = new OverlayItem(point, "Minha Casa", "Funfou");
    	    	
//    	GeoPoint point2 = new GeoPoint((int)(-8.055352 * 1E6), (int)(-34.920087 * 1E6));
//    	OverlayItem overlayitem2 = new OverlayItem(point2, "Eba", "Funfou de novo");
//    	
//    	GeoPoint point3 = new GeoPoint((int)(-8.049828 * 1E6), (int)(-34.922544 * 1E6));
//    	OverlayItem overlayitem3 = new OverlayItem(point3, "Mais um", "Funfou mais uma vez");
    	
		itemizedOverlay.addOverlay(overlayitem);
    	mapOverlays.add(itemizedOverlay);
    	
    	mapcontroller = mapa.getController();
    	mapcontroller.setZoom(17);
    	mapcontroller.setCenter(point);
    	
    	
	}
	
	private void initiatePopUpWindow(){
			try {
		        LayoutInflater inflater = (LayoutInflater) PrincipalActivity.this
		        		.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		        View layout = inflater.inflate(R.layout.popup, null);
		        pw = new PopupWindow(layout, 100, 50, true);
		        pw.showAtLocation(layout, Gravity.CENTER, 0, 0);
		        
		        txtLocal = (TextView) findViewById(R.id.textView1);
		        txtDesc = (TextView) findViewById(R.id.textView2);
		        Button btnCadastrar = (Button) findViewById(R.id.button1);
		        
		        
		        
		    } catch (Exception e) {
		        e.printStackTrace();
		    }
	}
	
	
	public void onLocationChanged(Location location) {
		
	}

	public void onProviderDisabled(String provider) {
		
	}

	public void onProviderEnabled(String provider) {
		
	}

	public void onStatusChanged(String provider, int status, Bundle extras) {
		
	}

	@Override
	protected boolean isRouteDisplayed() {
		return false;
	}
}